/*
 * SearchFactory.java
 *
 * Created on May 12, 2007, 5:35 PM
 *
 *  Life Logger v1.0
    Copyright (C) 2007  Anand Kishore (anand@semanticvoid.com)
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package com.semanticvoid.lifelogger.karma.search.factory;

import com.semanticvoid.lifelogger.configuration.Constants;
import com.semanticvoid.lifelogger.karma.search.factory.decorator.DateSorter;
import com.semanticvoid.lifelogger.karma.search.factory.decorator.Searcher;
import com.semanticvoid.lifelogger.karma.search.factory.decorator.TimeDamper;
import com.semanticvoid.lifelogger.karma.search.interfaces.ISearch;

/**
 *
 * @author anand kishore
 */
public class SearchFactory {
    
    /** Creates a new instance of SearchFactory */
    public SearchFactory() {
    }
    
    public ISearch produceSearcher(String... decorators) {
        // The core search (forms the base of all decorators)
        // If no decorators are specified then the factory returns
        // only the core searcher.
        ISearch searcher = new Searcher();
        
        if(decorators != null) {
            for(String decorator : decorators) {
                if(decorator.equalsIgnoreCase(Constants.DECORATOR_TIME_DAMPER)) {
                    searcher = new TimeDamper(searcher);
                } else if(decorator.equalsIgnoreCase(Constants.DECORATOR_TIME_SORT_ASC)) {
                    searcher = new DateSorter(searcher, Constants.SORT_ORDER_ASC);
                } else if(decorator.equalsIgnoreCase(Constants.DECORATOR_TIME_SORT_DESC)) {
                    searcher = new DateSorter(searcher, Constants.SORT_ORDER_DESC);
                }
            }
        }
        
        return searcher;
    }
}
